package mylab.base.foundation.lang;


import java.util.List;

import cn.hutool.core.collection.CollUtil;

public interface TreeNode<T> {
    T getNode();

    T getParent();

    List<T> getChildren();

    default int getChildrenSize() {
        return getChildren().size();
    }

    default TreeNode<T> addChild(T t) {
        if (t != null) {
            getChildren().add(t);
        }
        return this;
    }

    default TreeNode<T> addChildren(List<T> list) {
        if (CollUtil.isNotEmpty(list)) {
            getChildren().addAll(list);
        }
        return this;
    }

    default TreeNode<T> removeChild(T t) {
        if (t != null) {
            getChildren().remove(t);
        }
        return this;
    }

    default TreeNode<T> removeChildren(List<T> list) {
        if (CollUtil.isNotEmpty(list)) {
            getChildren().removeAll(list);
        }
        return this;
    }

    default TreeNode<T> clearChildren() {
        getChildren().clear();
        return this;
    }

}
